#! /bin/bash

. ./scripts/shell/common.sh
. ./scripts/shell/golang.sh
. ./scripts/shell/tool.sh


if [ -f "${PRE_HOOK}" ];then
. "${PRE_HOOK}"
fi

. ./scripts/shell/version.sh

REPO=$(${GIT} remote get-url origin)
NAME=$(${GIT} config user.name)
EMAIL=$(${GIT} config user.email)

AUTHOR="${NAME}(${EMAIL})"

echo "${YS_CLI} go build -r ${REPO} -a ${AUTHOR} -v ${VERSION}"

${YS_CLI} go build -r "${REPO}" -a "${AUTHOR}" -v "${VERSION}"

# 判断build 结果失败时 不执行hook
if [[ "$?" != 0 ]]
then
    exit 255
fi

# 复制资源文件
cp -r ./resource ./_out/${VERSION}/
tar -zcvf ./_out/${PROJECT_NAME}-${VERSION}.tar.gz -C ./_out/ ${VERSION}

if [ -f "${END_HOOK}" ];then
. "${END_HOOK}"
fi